package com.example.runningdemo.designModel.observer;

import java.util.Vector;

/**
 * @program: Running-Demo
 * @description:
 * @author: kangwei
 * @create: 2024-08-12 09:59
 **/
public class Subject {

    private Vector<Observer> observers = new Vector<>();

    /**
     * 注册观察者
     *
     * @param observer
     */
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    /**
     * 删除观察者
     *
     * @param observer
     */
    public void deleteObserver(Observer observer) {
        observers.remove(observer);
    }

    /**
     * 通知所有观察者
     *
     * @param state
     */
    public void notifyAllObserver(String state) {
        for (Observer observer1 : observers) {
            observer1.update(state);
        }
    }
}
